<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/5/29
 * Time: 20:33
 */

namespace Home\Model;


class BookManageModel extends BaseModel
{
    // 数据表名（不包含表前缀）
    protected $tableName        =   'bookinfo';

    /**
     * 查询所有书籍信息
     * @return array（）
    **/
    public function getAllBookInfo(){
        return $this->order('book_id DESC')->select();
    }
    /**
     * 根据条件书籍信息查询
     * @param Integer $book_id 图书ID
     * @return array()
    **/
    public function bookShowInfo($book_id){
        return $this->where("book_id=$book_id")->find();
    }
    /**
     * 书籍数量查询
     * @param Integer $book_id 图书ID
     * @return boolean
    **/
    public function getBookNumber($book_id){
        $bookId=$this->where("book_id=$book_id")->getField('book_number');
        if($bookId==0){
            return false;
        }else{
            return true;
        }
    }
    /**
     * 书籍数量变化
     * @param Integer $book_id 图书ID
     * @return boolean
    **/
    public function setBookNumber($book_id){
        $this->where("book_id=$book_id")->setDec('book_number');
        $this->where("book_id=$book_id")->setInc('book_borrow');
    }
    /**
     * 订单受理中，书籍数量虚减,销售书籍数量加
     * @param Integer $book_id 图书ID
    **/
    public function setBookNumberById($book_id){
        $this->where("book_id=$book_id")->setDec('book_number');
        $this->where("book_id=$book_id")->setInc('buy_book_number');
    }
    /**
     * 查询书籍表所有信息
     * @return array()
     **/
    public function getBookShowInfo($book_name,$book_type_id,$book_case_id,$book_isbn_id){
        $where=array();
        if(!empty($book_name)){
            $where['book_name']=array('LIKE',"%{$book_name}%");
        }
        if(!empty($book_type_id)){
            $where['book_type_id']=$book_type_id;
        }
        if(!empty($book_case_id)){
            $where['book_case_id']=$book_case_id;
        }
        if(!empty($book_isbn_id)){
            $where['book_ISBN_id']=$book_isbn_id;
        }
        $where['book_del']=1;
        return $this->where($where)->order('book_id DESC')->select();
    }

}